package designPattern.structure7.Decorator.chapter6_Decorator.test6_2;

public class Application {
    public static void main(String args[]) {

        Application client = new Application();

        System.out.println("--------6.2装饰模式的结构和使用---------");
        Sparrow sparrow = new Sparrow();
        SparrowDecorator sparrowDecorator1 = new SparrowDecorator(sparrow);
        SparrowDecorator sparrowDecorator2 = new SparrowDecorator(sparrowDecorator1);


        client.needBird(sparrow);
        client.needBird(sparrowDecorator1);
        client.needBird(sparrowDecorator2);


        System.out.println("--------6.3使用多个装饰者---------");
        Bird bird1 = new SparrowDecoratorTwo(sparrow);
        Bird bird2 = new SparrowDecorator(bird1);
        Bird bird3 = new SparrowDecorator(bird2);
        Bird bird4 = new SparrowDecoratorTwo(bird3);

        client.needBird(sparrow);
        client.needBird(bird1);
        client.needBird(bird2);
        client.needBird(bird3);
        client.needBird(bird4);

        System.out.println("--------6.4装饰模式相对于继承机制的优势---------");
        //飞行250米的小鸟
        Bird bird = new SparrowDecorator(new SparrowDecorator(new SparrowDecorator(new Sparrow())));
        client.needBird(bird);
    }

    public void needBird(Bird bird) {
        int flyDistance = bird.fly();
        System.out.println("这只鸟能飞行" + flyDistance + "米");
    }
}
 
  
